<?php
	
require_once( '../system/smarty.inc' );
//require_once( '../system/mdao/Class_M_USER.php' );
require_once( '../system/mdao/Class_AFCS_SV.php' );
require_once( '../system/mdao/Class_M_OTHER.php' );

require_once( '../system/Class_ERROR.php' );
require_once( '../system/login.inc.php' );
require_once( '../system/aoki_m.php' );
require_once( '../system/Class_PWD.php' );

Class_PWD::valid_auth(AOKI_AUTH_AFCS,$login['staff_auth']);

//if( $login['staff_auth'] != 'G-0' ) exit;


$dosearch = FALSE;

$dao = new Class_AFCS_SV;
$dao->do_debug();
//$dao = new Class_AFCS_SV;


//1．佐川印刷作成　一般　店舗明細一覧


if ( isset( $_GET['csv'] ) &&  (  $_GET['csv'] == "download" ) ||
	 isset( $_GET['hist'] ) &&  (  $_GET['hist'] == "2" ) ) {
	$forms =  $_SESSION['MSEARCH']['USER'];
}else {
	$forms = $_GET;
	$_SESSION['MSEARCH']['USER'] = $forms;
}


if ( isset( $forms['user_name'] ) &&  ( !empty( $forms['user_name'] ) ) ){
//	$wherearr[] = sprintf(" shop_cd like  '%s' ",  "%".$dao->esc( $forms['user_name'] )."%" );
	$wherearr[] = sprintf(" shop_cd = ".$dao->esc( $forms['user_name'] ) );
}

//日付修正１
if ( isset( $forms['upd_f'] ) &&  ( !empty( $forms['upd_f'] ) ) ){
//	$wherearr[] = Class_PWD::get_u_time_where_sql($forms['upd_f'], 1 );

		$the_time = str_replace( '/', '', $forms['upd_f']);
//			$the_time = $the_time. " 00:00:00";
//			if ($table) {
//				$wherearr[] = $table.".u_time >=  '{$the_time}'";
//			} else {
				$wherearr[] = " M_MATRIX_TERM.flier_date >=  '{$the_time}'";
//		}
}

//日付修正2
if ( isset( $forms['upd_t'] ) &&  ( !empty( $forms['upd_t'] ) ) ){

		$the_time = str_replace( '/', '', $forms['upd_t']);

//		$the_time = $the_time. " 23:59:59";
//		if ($table) {
//			$wherearr[] = $table.".u_time <=  '{$the_time}'";
//		}else {
			$wherearr[] = " M_MATRIX_TERM.flier_date <=  '{$the_time}'";
//		}
}




if ( isset( $forms['search'] ) && (  !empty( $forms['search'] ) ) ){
	$dosearch = TRUE;
}

if( isset( $forms['page'] ) && is_numeric( $forms['page'] ) ){
	$dosearch = TRUE;
	$page['current'] = $forms['page'];
	$st = ( $page['current'] -1 ) * PAGE_MAX;
}else{
	$page['current'] = 1;
	$st = 0;
}

$page['item'] = PAGE_MAX;
if ($dosearch) {
	//$page内容は関数内部更新されます。
	$data = $dao->search( $wherearr, $page );
}



//ここまで　佐川印刷作成　一般　店舗明細一覧




//GETにてsmartyにFORMの値を表示させるのに使用する。
if( isset($forms) ) $smarty->assign('forms', $forms);


//SQL文の結果をdataにいれておく
if( isset($data) ) $smarty->assign('data', $data);

//検索結果に対する、現在○ページの設定
if( isset($page) ) $smarty->assign('page', $page);


$smarty->assign('menu', $smarty->fetch('menu.html') );
$smarty->assign('logout', $smarty->fetch('logout.html') );
$smarty->assign('footer', $smarty->fetch('footer.html') );
$smarty->assign('pageing', $smarty->fetch('page.html') );
$smarty->display('afcs_adm_store_view.html');

?>